package com.xm.zcf.dao.admin.impl;

import com.xm.zcf.dao.admin.AdminDao;
import com.xm.zcf.domain.user.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/3/6.
 */
@Repository
public class AdminDaoImpl implements AdminDao {
    @Resource
    public SessionFactory sessionFactory;
    protected Session getSession(){
            Session session=sessionFactory.getCurrentSession();
            return  session;
    }

    @Override
    public User findByUsernamePassword(String username, String password) {
        User user=(User)getSession().createQuery(
                "from User u where u.password=?and u.username=?"
        ).setParameter(0,password)
         .setParameter(1,username)
         .uniqueResult();
        return user;
    }
}
